import turtle
import math

def draw_square(pen, x, y, length):
    pen.penup()
    pen.goto(x - length / 2, y - length / 2)
    pen.pendown()
    for _ in range(4):
        pen.forward(length)
        pen.left(90)

def draw_board(pen, j):
    pen.color('black')
    pen.pensize(1)

    length_j = 50 * (j + 1)

    center_x = 0
    center_y = 0

    if j > 0:
        center_x += 150 * j

    # 绘制开始的三个方块
    for i in range(3):
        length_i = 50 * (i + 1)
        draw_square(pen, center_x, center_y, length_i)

    if j > 0:
        # 连接三个正方形的四边
        pen.penup()
        pen.goto(center_x - 50, center_y + 50)
        pen.pendown()
        pen.setheading(0)
        pen.forward(length_j)

        pen.penup()
        pen.goto(center_x + 50, center_y + 50)
        pen.pendown()
        pen.setheading(90)
        pen.forward(length_j)

        pen.penup()
        pen.goto(center_x + 50, center_y - 50)
        pen.pendown()
        pen.setheading(180)
        pen.forward(length_j)

    # 绘制红色的方块
    pen.color('red')
    pen.pensize(3)
    draw_square(pen, center_x - 50, center_y - 50, 100)

canvas = turtle.Screen()
pen = turtle.Turtle()

draw_board(pen, 0)
draw_board(pen, 1)

canvas.exitonclick()
